<?php

namespace App\Utils;

final class OptionUtil
{
    const OPTION_NAME_ORGANIZATION_CODE = 'organizationCode';
    const OPTION_NAME_CERTIFICATION     = 'certification';
    const OPTION_NAME_AGREEMENT_ORIGIN  = 'agreementOrigin';
    const OPTION_NAME_AUDIT_TYPE        = 'auditType';

    /** @var string[] 组织性质代码名称 */
    public static $organizationCodeMap = [
        10 => "有限责任公司",
        11 => "股份有限公司",
        12 => "私营企业",
        1  => "政府机关",
        6  => "国有企业",
        2  => "事业单位",
        25 => "外资企业",
        26 => "外商投资股份有限公司",
        3  => "社会团体",
        4  => "企业组织",
        5  => "内资企业",
        7  => "集体企业",
        8  => "股份合作企业",
        9  => "联营企业",
        13 => "全民所有制企业",
        14 => "合伙企业",
        15 => "个人独资企业",
        16 => "其他企业",
        17 => "港、澳、台商投资企业",
        18 => "合资经营企业（港或澳、台资）",
        19 => "合作经营企业（港或澳、台资）",
        20 => "港、澳、台商独资经营企业",
        21 => "港、澳、台商投资股份有限公司",
        22 => "外商投资企业",
        23 => "中外合资经营企业",
        24 => "中外合作经营企业",
        27 => "其他组织",
    ];

    /** @var string[] 认证名称 */
    public static $certificationMap = [
        12  => "QMS2015",
        22  => "EMS2015",
        32  => "OHSMS2018",
        42  => "EC9000",
        71  => "FSMS2018",
        81  => "HACCP2021",
        91  => "MDQMS2016",
        18  => "EnMS2018",
        222 => "JQ2017",
    ];

    public static $agreementOriginMap = [
        1  => "总部",
        9  => "天津合作方",
        8  => "南京合作方",
        7  => "晟标合作方",
        6  => "温州分公司",
        10 => "宁夏合作方",
        11 => "黄石合作方",
        12 => "武汉合作方2",
        13 => "河南合作方",
        14 => "安徽合作方",
        15 => "武汉合作方",
        17 => "成都合作方",
        18 => "湖北合作方",
        19 => "广东合作方",
        20 => "青海合作方",
        21 => "甘肃合作方",
    ];

    public static $auditTypeMap = [
        1 => "初审",
        4 => "监一",
        5 => "监二",
        6 => "再认证",
    ];

    public static function getOptionNameByKey($flag, $key)
    {
        $options = self::getOptionMap($flag);

        if (!array_key_exists($key, $options)) {
            throw new \Exception("键值不存在");
        }

        return $options[$key];
    }

    public static function getOptionMap($flag)
    {
        switch ($flag) {
            case self::OPTION_NAME_ORGANIZATION_CODE:
                return self::$organizationCodeMap;
            case self::OPTION_NAME_CERTIFICATION:
                return self::$certificationMap;
            case self::OPTION_NAME_AGREEMENT_ORIGIN:
                return self::$agreementOriginMap;
            case self::OPTION_NAME_AUDIT_TYPE:
                return self::$auditTypeMap;
        }

        return [];
    }
}
